package com.jincp.image.pick.ui.video;

import android.os.Bundle;
import android.view.View;

import com.jincp.image.pick.FileBaseActivity;
import com.jincp.image.R;
import com.jincp.image.pick.VideoPicker;
import com.jincp.image.pick.adapter.video.VideoPageAdapter;
import com.jincp.image.pick.bean.VideoItem;
import com.jincp.image.pick.view.ViewPagerFixed;

import java.util.ArrayList;

/**
 * ================================================
 * 作    者：jeasonlzy（廖子尧 Github地址：https://github.com/jeasonlzy0216
 * 版    本：1.0
 * 创建日期：2016/5/19
 * 描    述：
 * 修订历史：视频预览的基类
 * ================================================
 */
public abstract class VideoPreviewBaseActivity extends FileBaseActivity {

    protected VideoPicker videoPicker;
    protected ArrayList<VideoItem> mVideoItems;      //跳转进VideoPreviewFragment的视频文件夹
    protected int mCurrentPosition = 0;              //跳转进VideoPreviewFragment时的序号，第几个视频
    protected ArrayList<VideoItem> selectedVideos;   //所有已经选中的视频
    protected View content;
    protected ViewPagerFixed mViewPager;
    protected VideoPageAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_preview);

        mCurrentPosition = getIntent().getIntExtra(VideoPicker.EXTRA_SELECTED_VIDEO_POSITION, 0);
        mVideoItems = (ArrayList<VideoItem>) getIntent().getSerializableExtra(VideoPicker.EXTRA_VIDEO_ITEMS);
        videoPicker = VideoPicker.getInstance();
        selectedVideos = videoPicker.getSelectedVideos();

        //初始化控件
        content = findViewById(R.id.content);

        findViewById(R.id.btn_ok).setVisibility(View.GONE);

        mViewPager = (ViewPagerFixed) findViewById(R.id.viewpager);
        mAdapter = new VideoPageAdapter(this, mVideoItems);
        mAdapter.setPhotoViewClickListener(new VideoPageAdapter.PhotoViewClickListener() {
            @Override
            public void OnPhotoTapListener(View view) {
                onVideoSingleTap();
            }
        });
        mViewPager.setAdapter(mAdapter);
        mViewPager.setCurrentItem(mCurrentPosition, false);

        //初始化当前页面的状态
        getToolbar().setTitle(getString(R.string.preview_image_count, mCurrentPosition + 1, mVideoItems.size()));
    }

    /** 单击时，隐藏头和尾 */
    public abstract void onVideoSingleTap();
}